package com.serkol.ams.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.ams.entity.PosterImage;
import com.serkol.ams.mapper.PosterImageMapper;
import com.serkol.ams.service.PosterImageService;
import com.serkol.handler.MyLambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author pingan
* @description 针对表【poster_image】的数据库操作Service实现
* @createDate 2022-11-14 22:52:10
*/
@Service
public class PosterImageServiceImpl extends ServiceImpl<PosterImageMapper, PosterImage>
    implements PosterImageService{

    @Override
    public List<Map<String, Object>> findByDataList(long id) {
        MyLambdaQueryWrapper<PosterImage> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(PosterImage::getId).as("id").picture(PosterImage::getImageId).as("url");
        queryWrapper.eq(PosterImage::getPosterId,id);
        queryWrapper.orderByDesc(PosterImage::getId);

        return this.baseMapper.selectMaps(queryWrapper);
    }

    @Override
    public Map<String, Object> findByGetId(long id) {
        MyLambdaQueryWrapper<PosterImage> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(PosterImage::getId).as("id").picture(PosterImage::getImageId).as("url");
        queryWrapper.eq(PosterImage::getId,id);
        queryWrapper.orderByDesc(PosterImage::getId);
        return this.getMap(queryWrapper);
    }

    @Override
    public Map<String, Object> findByGetTypeRand(int type) {
        MyLambdaQueryWrapper<PosterImage> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(PosterImage::getId).as("id").picture(PosterImage::getImageId).as("url");
        queryWrapper.eq(PosterImage::getType,type);
      //  queryWrapper.orderByDesc(PosterImage::getId);

        queryWrapper.last(" ORDER BY RAND() LIMIT 1");
        return this.getMap(queryWrapper);
    }

    @Override
    public List<Map<String, Object>> findByDataMiniTypeList(int type) {
        MyLambdaQueryWrapper<PosterImage> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(PosterImage::getId).as("id").picture(PosterImage::getImageId).as("url");
        queryWrapper.eq(PosterImage::getType,type);
        queryWrapper.orderByDesc(PosterImage::getId);

        return this.baseMapper.selectMaps(queryWrapper);
    }
}




